package com.sky.mapper;

import com.sky.entity.AddressBook;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressBookMapper {
    // 新增地址
    @Insert("insert into address_book (user_id, consignee, sex, phone, province_name, province_code, city_name, city_code, district_name, district_code, detail, label, is_default) " +
            "values" +
            " (#{userId}, #{consignee}, #{sex}, #{phone}, #{provinceName}, #{provinceCode},#{cityName}, #{cityCode}, #{districtName}, #{districtCode},#{detail},#{label},#{isDefault})")
    void insert(AddressBook addressBook);

    // 条件查询
    List<AddressBook> list(AddressBook addressBook);
    // 根据id查询地址
    @Select("select * from address_book where id = #{id}")
    AddressBook getById(Long id);
    // 根据id修改地址
    void update(AddressBook addressBook);
    // 设置当前用户的默认地址状态
    @Update("update address_book set is_default = #{isDefault} where user_id = #{userId}")
    void updateIsDefaultByUserId(AddressBook addressBook);
    // 根据id删除地址
    @Delete("delete from address_book where id = #{id}")
    void deleteById(Long id);
}
